/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.hvtt.web.controller;

import com.hvtt.web.connection.Command;
import com.hvtt.web.connection.WEBConnection;
import com.hvtt.web.connection.WEBParamCollection;
import com.hvtt.web.controllerUtils.MainController;
import com.hvtt.web.controllerUtils.UtilsController;
import com.hvtt.web.models.RPT_ThongKeKhacModel;
import com.hvtt.web.models.RPT_ThongKeNapTienModel;
import com.hvtt.web.models.RPT_ThongKeTaiKhoanModel;
import com.hvtt.web.models.RPT_TongCashoutModel;
import com.hvtt.web.models.RPT_TongDoanhThuModel;
import com.hvtt.web.models.RPT_TongTienNapModel;
import com.hvtt.web.models.clsCP;
import com.hvtt.web.models.clsCongTT;
import com.hvtt.web.models.clsGame;
import com.hvtt.web.models.datatable.DefaultLazyDataModel;
import com.hvtt.web.utilities.Utilities;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.component.html.HtmlOutputText;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.ComponentSystemEvent;
import org.apache.commons.lang3.StringUtils;
import org.primefaces.component.column.Column;
import org.primefaces.component.panelgrid.PanelGrid;
import org.primefaces.component.row.Row;
import org.primefaces.context.RequestContext;
import org.primefaces.event.NodeExpandEvent;
import org.primefaces.model.DefaultTreeNode;
import org.primefaces.model.LazyDataModel;
import org.primefaces.model.StreamedContent;
import org.primefaces.model.TreeNode;
import org.primefaces.model.chart.BarChartSeries;
import org.primefaces.model.chart.CartesianChartModel;
import org.primefaces.model.chart.ChartModel;


import org.primefaces.model.chart.ChartSeries;
import org.primefaces.model.chart.LineChartSeries;
import org.primefaces.model.chart.PieChartModel;

/**
 *
 * @author Administrator
 */
@ManagedBean
@SessionScoped
public class ReportController implements Serializable {

    private WEBConnection DAL = WEBConnection.getInstance();
    ReportEcxelController controller;
    private StreamedContent fileExporter;
    private String cpid = "";
    private String hdh = "";
    private String gameID = "";
    private String congTT = "";
    private String telco = "";
    private String loaiThongKe = "";
    private Date tuNgay = Calendar.getInstance().getTime();
    private Date denNgay = new java.sql.Date(0);
    private long giaTriTheNap = 0;
    private String page = "";
    private String loaiBD = "";
    
    private long tong1=0;
    private long tong2=0;
    private long tong3=0;
    private long tong4=0;
            

    public String getPage() {
        return page;
    }

    public void setPage(String page) {
        this.page = page;
    }
    MainController mainController;
    UtilsController utilsController;
    //data table
 
    public ReportController() {
        mainController = Utilities.getManagedBean(MainController.class);
        utilsController = Utilities.getManagedBean(UtilsController.class);
        controller = new ReportEcxelController();
    }

    public List<clsCP> findAllCP() throws SQLException {
        List<clsCP> lst;
        if (Sys_NguoiDungController.findUser().isIsAdmin()) {
            lst = DAL.executeQuery("Select distinct users_report.CPID,users_report.CPName as CPName from users_report where users_report.CPID<>''", clsCP.class);
        } else {
            WEBParamCollection Params = WEBParamCollection.getInstance();
            Params.add(Sys_NguoiDungController.findUser().getUserID());
            lst = DAL.executeQuery("Select distinct users_report.CPID,users_report.CPName as CPName from users_report where users_report.UserID=?", Command.sqlText, Params, clsCP.class);
        }
        return lst == null ? new ArrayList() : lst;
    }
    
     public List<clsCongTT> findAllCongTT() throws SQLException {
        List<clsCongTT> lst;
        lst = DAL.executeQuery("Select distinct AgentInfo.AgentID,AgentInfo.AgentName from AgentInfo", clsCongTT.class);
        return lst == null ? new ArrayList() : lst;
    }

      public List<clsGame> findAllGames() throws SQLException {
        List<clsGame> lst;
        lst = DAL.executeQuery("Select distinct GameInfo.GameID,GameInfo.GameName from GameInfo", clsGame.class);
        return lst == null ? new ArrayList() : lst;
    }
    
    
//    public List<RPT_TongTienNapModel> RPT_TongTienNap() throws SQLException {
//        List<RPT_TongTienNapModel> lst = new ArrayList();
//        WEBParamCollection Params = new WEBParamCollection();
//        Params.add(this.getCpid());
//        Params.add(this.getGameID());
//        Params.add(this.getHdh());
//        Params.add(this.getTelco());
//        Params.add(this.getCongTT());
//        Params.add(this.getGiaTriTheNap());
//        Params.add(this.getTuNgay());
//        Params.add(this.getDenNgay());
//        lst = DAL.executeQuery("{call RPT_TongTienNap(?,?,?,?,?,?,?,?)}", Command.sqlStoredProcedure, Params, RPT_TongTienNapModel.class);
//
//        return lst;
//
//    }
  
  
    
    
    
    
    
    
    public List<RPT_ThongKeKhacModel> RPT_ThongKeKhac() throws SQLException {
        List<RPT_ThongKeKhacModel> lst = new ArrayList();
        WEBParamCollection Params = new WEBParamCollection();
        Params.add(("-1".equals(this.getCpid()) ? "" : this.getCpid()));
        Params.add(("-1".equals(this.getGameID()) ? "" : this.getGameID()));
        Params.add(("-1".equals(this.getLoaiThongKe()) ? "" : this.getLoaiThongKe()));
        Params.add(this.getTuNgay());
        Params.add(this.getDenNgay());
        lst = DAL.executeQuery("{call RPT_ThongKeKhac(?,?,?,?,?)}", Command.sqlStoredProcedure, Params, RPT_ThongKeKhacModel.class);

        return lst;
    }

    
    public TreeNode RPT_ThongKeKhac_ThongKe() throws SQLException {
        TreeNode root = new DefaultTreeNode(new RPT_ThongKeTaiKhoanModel(), null);
        WEBParamCollection Params = new WEBParamCollection();
        Params.add(("-1".equals(this.getCpid()) ? "" : this.getCpid()));
        Params.add(("-1".equals(this.getGameID()) ? "" : this.getGameID()));
        Params.add(("-1".equals(this.getLoaiThongKe()) ? "" : this.getLoaiThongKe()));
        Params.add(this.getTuNgay());
        Params.add(this.getDenNgay());
        List<RPT_ThongKeKhacModel>lst = DAL.executeQuery("{call RPT_ThongKeKhac(?,?,?,?,?)}", Command.sqlStoredProcedure, Params, RPT_ThongKeKhacModel.class);

        int i = 0;
        long lTong1=0;
        
        String strCPID;
        while (i < lst.size()) {
            RPT_ThongKeKhacModel m = new RPT_ThongKeKhacModel();
            m.setCpName(lst.get(i).getCpName());
            TreeNode noteParent = new DefaultTreeNode(m, root);
            noteParent.setExpanded(true);


            strCPID = lst.get(i).getCpid();

            int iCount = 0;
            if (i < lst.size()) {
                while (i < lst.size() && (lst.get(i).getCpid() == null ? strCPID == null : lst.get(i).getCpid().equals(strCPID))) {
                    lst.get(i).setCpName("");
                    noteParent.getChildren().add(new DefaultTreeNode(lst.get(i)));
                    iCount += lst.get(i).getSoLuong();
                    lTong1+=lst.get(i).getSoLuong();
                    i++;
                }
                m.setSoLuong(0);
            }
            // i++;
        }
        this.setTong1(lTong1);
        
        return root;
    }
    public TreeNode RPT_ThongKeKhac_ThongKe_ARPU() throws SQLException {
        TreeNode root = new DefaultTreeNode(new RPT_ThongKeTaiKhoanModel(), null);
        WEBParamCollection Params = new WEBParamCollection();
        Params.add(("-1".equals(this.getCpid()) ? "" : this.getCpid()));
        Params.add(("-1".equals(this.getGameID()) ? "" : this.getGameID()));
        Params.add(("-1".equals(this.getLoaiThongKe()) ? "" : this.getLoaiThongKe()));
        Params.add(this.getTuNgay());
        Params.add(this.getDenNgay());
        List<RPT_ThongKeKhacModel>lst = DAL.executeQuery("{call RPT_ThongKeKhac(?,?,?,?,?)}", Command.sqlStoredProcedure, Params, RPT_ThongKeKhacModel.class);

        int i = 0;
        long lTong1=0;
        long lTongSoLuong=0;
        
        String strCPID;
        while (i < lst.size()) {
            RPT_ThongKeKhacModel m = new RPT_ThongKeKhacModel();
            m.setCpName(lst.get(i).getCpName());
            TreeNode noteParent = new DefaultTreeNode(m, root);
            noteParent.setExpanded(true);


            strCPID = lst.get(i).getCpid();

            long lARPU=0;
           
            if (i < lst.size()) {
                while (i < lst.size() && (lst.get(i).getCpid() == null ? strCPID == null : lst.get(i).getCpid().equals(strCPID))) {
                                     
                    
                    String strThang = lst.get(i).getThang();
                        RPT_ThongKeKhacModel m_thang = new RPT_ThongKeKhacModel();
                        m_thang.setCpName(lst.get(i).getThang());
                        m_thang.setThang("");

                        TreeNode noteParent_Thang = new DefaultTreeNode(m_thang, noteParent);
                        noteParent_Thang.setExpanded(true);
                        long lARPU_Thang=0;
                        long lTongSoUserTheoThang=0;
                        
                        while (i < lst.size() && (lst.get(i).getThang()== null ? strThang == null : lst.get(i).getThang().equals(strThang))
                                && (lst.get(i).getCpid() == null ? strCPID == null : lst.get(i).getCpid().equals(strCPID))
                                ) {
                           
                            lst.get(i).setCpName(Utilities.parseDateTime(lst.get(i).getNgay(),"dd/MM/yyyy"));
                            //lst.get(i).setTelco("");
//                            
                            RPT_ThongKeKhacModel m1 = lst.get(i);
                            noteParent_Thang.getChildren().add(new DefaultTreeNode(m1));
                            
                            m1.setArpu(lst.get(i).getSoTien()/(lst.get(i).getSoLuong()==0?1:lst.get(i).getSoLuong()));

                            
//                            lSoTien_Thang +=lst.get(i).getSoTien();
//                            lSoLuong_Thang+=lst.get(i).getSoLuong();
//                            
                           lARPU_Thang+=lst.get(i).getSoTien();
                           lARPU+=lst.get(i).getSoTien();
                           lTong1+=lst.get(i).getSoTien();
                           lTongSoLuong=lst.get(i).getTongCong();
                           lTongSoUserTheoThang=lst.get(i).getTongSoLuongThang();
                            m1.setSoTien(lst.get(i).getSoTien());
                           i++;
                                
                          
                           
                        }
                      
                         m_thang.setArpu(lARPU_Thang/(lTongSoUserTheoThang<=0?1:lTongSoUserTheoThang));
                         
                    
                }
                        
                m.setArpu(lARPU/(lTongSoLuong<=0?1:lTongSoLuong));
                
            }
            // i++;
        }
        this.setTong1(lTong1/(lTongSoLuong<=0?1:lTongSoLuong));
        
        
        return root;
    }
    public TreeNode RPT_ThongKeKhac_ThongKe_BIT() throws SQLException {
        TreeNode root = new DefaultTreeNode(new RPT_ThongKeTaiKhoanModel(), null);
        WEBParamCollection Params = new WEBParamCollection();
        Params.add(("-1".equals(this.getCpid()) ? "" : this.getCpid()));
        Params.add(("-1".equals(this.getGameID()) ? "" : this.getGameID()));
        Params.add(("-1".equals(this.getLoaiThongKe()) ? "" : this.getLoaiThongKe()));
        Params.add(this.getTuNgay());
        Params.add(this.getDenNgay());
        List<RPT_ThongKeKhacModel>lst = DAL.executeQuery("{call RPT_ThongKeKhac(?,?,?,?,?)}", Command.sqlStoredProcedure, Params, RPT_ThongKeKhacModel.class);

        int i = 0;
        long lTong1=0;
       
        
        String strCPID;
        while (i < lst.size()) {
            RPT_ThongKeKhacModel m = new RPT_ThongKeKhacModel();
            m.setCpName(lst.get(i).getCpName());
            TreeNode noteParent = new DefaultTreeNode(m, root);
            noteParent.setExpanded(true);


            strCPID = lst.get(i).getCpid();

            long lSoTien=0;
           
            if (i < lst.size()) {
                while (i < lst.size() && (lst.get(i).getCpid() == null ? strCPID == null : lst.get(i).getCpid().equals(strCPID))) {
                                     
                    
                    lst.get(i).setCpName(Utilities.parseDateTime(lst.get(i).getNgay(),"dd/MM/yyyy"));
                    //lst.get(i).setTelco("");
//                            
                    RPT_ThongKeKhacModel m1 = lst.get(i);
                    noteParent.getChildren().add(new DefaultTreeNode(m1));

                    //m1.setArpu(lst.get(i).getSoTien()/lst.get(i).getSoLuong());


//                            lSoTien_Thang +=lst.get(i).getSoTien();
//                            lSoLuong_Thang+=lst.get(i).getSoLuong();
//                            
                   //lARPU_Thang+=lst.get(i).getSoTien()/lst.get(i).getSoLuong();
                   lSoTien+=lst.get(i).getSoTien();
                   lTong1+=lst.get(i).getSoTien();

                    m1.setSoTien(lst.get(i).getSoTien());
                   i++;
                         
                    
                }
                        
                m.setSoTien(lSoTien);
                
            }
            // i++;
        }
        this.setTong1(lTong1);
        
        
        return root;
    }
    public TreeNode RPT_ThongKeKhac_ThongKe_BAC() throws SQLException {
        TreeNode root = new DefaultTreeNode(new RPT_ThongKeTaiKhoanModel(), null);
        WEBParamCollection Params = new WEBParamCollection();
        Params.add(("-1".equals(this.getCpid()) ? "" : this.getCpid()));
        Params.add(("-1".equals(this.getGameID()) ? "" : this.getGameID()));
        Params.add(("-1".equals(this.getLoaiThongKe()) ? "" : this.getLoaiThongKe()));
        Params.add(this.getTuNgay());
        Params.add(this.getDenNgay());
        List<RPT_ThongKeKhacModel>lst = DAL.executeQuery("{call RPT_ThongKeKhac(?,?,?,?,?)}", Command.sqlStoredProcedure, Params, RPT_ThongKeKhacModel.class);

        int i = 0;
        long lTong1=0;
       
        
        String strCPID;
        while (i < lst.size()) {
            RPT_ThongKeKhacModel m = new RPT_ThongKeKhacModel();
            m.setCpName(lst.get(i).getCpName());
            TreeNode noteParent = new DefaultTreeNode(m, root);
            noteParent.setExpanded(true);


            strCPID = lst.get(i).getCpid();

            long lSoTien=0;
           
            if (i < lst.size()) {
                while (i < lst.size() && (lst.get(i).getCpid() == null ? strCPID == null : lst.get(i).getCpid().equals(strCPID))) {
                                     
                    
                    lst.get(i).setCpName(Utilities.parseDateTime(lst.get(i).getNgay(),"dd/MM/yyyy"));
                    //lst.get(i).setTelco("");
//                            
                    RPT_ThongKeKhacModel m1 = lst.get(i);
                    noteParent.getChildren().add(new DefaultTreeNode(m1));

                    //m1.setArpu(lst.get(i).getSoTien()/lst.get(i).getSoLuong());


//                            lSoTien_Thang +=lst.get(i).getSoTien();
//                            lSoLuong_Thang+=lst.get(i).getSoLuong();
//                            
                   //lARPU_Thang+=lst.get(i).getSoTien()/lst.get(i).getSoLuong();
                   lSoTien+=lst.get(i).getSoTien();
                   lTong1+=lst.get(i).getSoTien();

                    m1.setSoTien(lst.get(i).getSoTien());
                   i++;
                         
                    
                }
                        
                m.setSoTien(lSoTien);
                
            }
            // i++;
        }
        this.setTong1(lTong1);
        
        
        return root;
    }
    
    
    
    public PieChartModel RPT_ThongKeKhac_Chart() throws SQLException {
        PieChartModel c = new PieChartModel();
        List<RPT_ThongKeKhacModel> lst;

        
        WEBParamCollection Params = new WEBParamCollection();
        Params.add(("-1".equals(this.getCpid()) ? "" : this.getCpid()));
        Params.add(("-1".equals(this.getGameID()) ? "" : this.getGameID()));
        Params.add(("-1".equals(this.getLoaiThongKe()) ? "" : this.getLoaiThongKe()));
        Params.add(this.getTuNgay());
        Params.add(this.getDenNgay());
        lst = DAL.executeQuery("{call RPT_ThongKeKhac_Chart(?,?,?,?,?)}", Command.sqlStoredProcedure, Params, RPT_ThongKeKhacModel.class);


        for (RPT_ThongKeKhacModel m : lst) {
           c.set(m.getCpName(), m.getSoLuong());
        }

        return c;
    }
    
    public CartesianChartModel RPT_ThongKeKhac_Chart_DAU_line_ngay() throws SQLException {
        CartesianChartModel c = new CartesianChartModel();
        List<RPT_ThongKeKhacModel> lst;

        WEBParamCollection Params = WEBParamCollection.getInstance();
        Params.add(("-1".equals(this.getCpid()) ? "" : this.getCpid()));
        Params.add(("-1".equals(this.getGameID()) ? "" : this.getGameID()));
        Params.add(this.getTuNgay());
        Params.add(this.getDenNgay());
        lst = DAL.executeQuery("{call RPT_ThongKeKhac_Chart_ngay_DAU(?,?,?,?)}", Command.sqlStoredProcedure, Params, RPT_ThongKeKhacModel.class);


        if(Sys_NguoiDungController.findUser().isIsAdmin())
        {
            List<RPT_ThongKeKhacModel> lst1=DAL.executeQuery("Select distinct CPID,CPName from users_report where users_report.CPID<>''",RPT_ThongKeKhacModel.class);
            for(RPT_ThongKeKhacModel m:lst1)
            {
                LineChartSeries l=new LineChartSeries();
                l.setLabel("Số user theo " + m.getCpName());
                int i=0;
                boolean bln=false;
                while(i<lst.size())
                {
                     if(!l.getData().containsKey(Utilities.parseDateTime(lst.get(i).getNgay(), "dd/MM")))
                    {
                        l.set(Utilities.parseDateTime(lst.get(i).getNgay(), "dd/MM"), 0);
                        l.setShowLine(true);
                    }
                    if(lst.get(i).getCpid() == null ? m.getCpid() == null : lst.get(i).getCpid().equals(m.getCpid()))
                    {
                         l.set(Utilities.parseDateTime(lst.get(i).getNgay(), "dd/MM"), lst.get(i).getSoLuong());
                         l.setShowLine(true);
                         bln=true;
                    }
                    i++;
                    
                   
                }
                  if(bln)
                    c.addSeries(l);
            }
            
            LineChartSeries l1=new LineChartSeries();
            l1.setLabel("Tổng số user");
            int i=0;
            while(i<lst.size())
            {

                  l1.set(Utilities.parseDateTime(lst.get(i).getNgay(), "dd/MM"), lst.get(i).getTongCong());
                 l1.setShowLine(true);
                     i++;
             
                  
            }
            
            
             c.addSeries(l1);
        }
        else
        {
            LineChartSeries l=new LineChartSeries();
            //LineChartSeries l1=new LineChartSeries();

            boolean bln=false;
            //l1.setLabel("Tổng số user nạp tiền");
          for (RPT_ThongKeKhacModel m : lst) {
              if(!bln)
              {
                  l.setLabel("CP Name " + m.getCpName());
                  bln=true;
              }
              l.setShowLine(true);
              l.set(Utilities.parseDateTime(m.getNgay(), "dd/MM"), m.getSoLuong());

//              l1.setShowLine(true);
//              l1.set(m.getThoiGian(), m.getTongCong());

          }
          c.addSeries(l);
         // c.addSeries(l1);

        }
        
      
        return c;
    }
     
    public CartesianChartModel RPT_ThongKeKhac_Chart_DAU_line_thang() throws SQLException {
        CartesianChartModel c = new CartesianChartModel();
        List<RPT_ThongKeKhacModel> lst;

        WEBParamCollection Params = WEBParamCollection.getInstance();
        Params.add(("-1".equals(this.getCpid()) ? "" : this.getCpid()));
        Params.add(("-1".equals(this.getGameID()) ? "" : this.getGameID()));
        Params.add(this.getTuNgay());
        Params.add(this.getDenNgay());
        lst = DAL.executeQuery("{call RPT_ThongKeKhac_Chart_thang_DAU(?,?,?,?)}", Command.sqlStoredProcedure, Params, RPT_ThongKeKhacModel.class);


        if(Sys_NguoiDungController.findUser().isIsAdmin())
        {
            List<RPT_ThongKeKhacModel> lst1=DAL.executeQuery("Select distinct CPID,CPName from users_report where users_report.CPID<>''",RPT_ThongKeKhacModel.class);
            for(RPT_ThongKeKhacModel m:lst1)
            {
                LineChartSeries l=new LineChartSeries();
                l.setLabel("Số user theo " + m.getCpName());
                int i=0;
                boolean bln=false;
                while(i<lst.size())
                {
                     if(!l.getData().containsKey(lst.get(i).getThang()))
                    {
                        l.set(lst.get(i).getThang(), 0);
                        l.setShowLine(true);
                    }
                    if(lst.get(i).getCpid() == null ? m.getCpid() == null : lst.get(i).getCpid().equals(m.getCpid()))
                    {
                         l.set(lst.get(i).getThang(), lst.get(i).getSoLuong());
                         l.setShowLine(true);
                         bln=true;
                    }
                    i++;
                    
                   
                }
                  if(bln)
                    c.addSeries(l);
            }
            
            LineChartSeries l1=new LineChartSeries();
            l1.setLabel("Tổng số user");
            int i=0;
            while(i<lst.size())
            {

                  l1.set(lst.get(i).getThang(), lst.get(i).getTongCong());
                 l1.setShowLine(true);
                     i++;
             
                  
            }
            
            
             c.addSeries(l1);
        }
        else
        {
            LineChartSeries l=new LineChartSeries();
            //LineChartSeries l1=new LineChartSeries();

            boolean bln=false;
            //l1.setLabel("Tổng số user nạp tiền");
          for (RPT_ThongKeKhacModel m : lst) {

              if(!bln)
              {
                  l.setLabel("CP Name " + m.getCpName());
                  bln=true;
              }
              l.setShowLine(true);
              l.set(m.getThang(), m.getSoLuong());

//              l1.setShowLine(true);
//              l1.set(m.getThoiGian(), m.getTongCong());

          }
          c.addSeries(l);
         // c.addSeries(l1);

        }
        
      
        return c;
    }
    
    
    public CartesianChartModel RPT_ThongKeKhac_Chart_ARPU_line_ngay() throws SQLException {
        CartesianChartModel c = new CartesianChartModel();
        List<RPT_ThongKeKhacModel> lst;

        WEBParamCollection Params = WEBParamCollection.getInstance();
        Params.add(("-1".equals(this.getCpid()) ? "" : this.getCpid()));
        Params.add(("-1".equals(this.getGameID()) ? "" : this.getGameID()));
        Params.add(this.getTuNgay());
        Params.add(this.getDenNgay());
        lst = DAL.executeQuery("{call RPT_ThongKeKhac_Chart_ngay_ARPU(?,?,?,?)}", Command.sqlStoredProcedure, Params, RPT_ThongKeKhacModel.class);


        if(Sys_NguoiDungController.findUser().isIsAdmin())
        {
            List<RPT_ThongKeKhacModel> lst1=DAL.executeQuery("Select distinct CPID,CPName from users_report where users_report.CPID<>''",RPT_ThongKeKhacModel.class);
            for(RPT_ThongKeKhacModel m:lst1)
            {
                LineChartSeries l=new LineChartSeries();
                l.setLabel("Số ARPU theo " + m.getCpName());
                int i=0;
                boolean bln=false;
                while(i<lst.size())
                {
                     if(!l.getData().containsKey(Utilities.parseDateTime(lst.get(i).getNgay(), "dd/MM")))
                    {
                        l.set(Utilities.parseDateTime(lst.get(i).getNgay(), "dd/MM"), 0);
                        l.setShowLine(true);
                    }
                    if(lst.get(i).getCpid() == null ? m.getCpid() == null : lst.get(i).getCpid().equals(m.getCpid()))
                    {
                         l.set(Utilities.parseDateTime(lst.get(i).getNgay(), "dd/MM"), lst.get(i).getSoTien()/(lst.get(i).getSoLuong()<=0?1:lst.get(i).getSoLuong()));
                         l.setShowLine(true);
                         bln=true;
                    }
                    i++;
                    
                   
                }
                  if(bln)
                    c.addSeries(l);
            }
            
            LineChartSeries l1=new LineChartSeries();
            l1.setLabel("Tổng số ARPU");
            int i=0;
            while(i<lst.size())
            {
                  l1.set(Utilities.parseDateTime(lst.get(i).getNgay(), "dd/MM"), lst.get(i).getTongCong());
                 l1.setShowLine(true);
                     i++;
            }
            
            
             c.addSeries(l1);
        }
        else
        {
            LineChartSeries l=new LineChartSeries();
            //LineChartSeries l1=new LineChartSeries();

            boolean bln=false;
            //l1.setLabel("Tổng số user nạp tiền");
          for (RPT_ThongKeKhacModel m : lst) {
             if(!bln)
             {
                 l.setLabel("CP Name " + m.getCpName());
                 bln=true;
             }
              l.setShowLine(true);
              l.set(Utilities.parseDateTime(m.getNgay(), "dd/MM"), m.getSoTien()/(m.getSoLuong()<=0?1:m.getSoLuong()));

//              l1.setShowLine(true);
//              l1.set(m.getThoiGian(), m.getTongCong());

          }
          c.addSeries(l);
         // c.addSeries(l1);

        }
        
      
        return c;
    }
    public CartesianChartModel RPT_ThongKeKhac_Chart_ARPU_line_thang() throws SQLException {
        CartesianChartModel c = new CartesianChartModel();
        List<RPT_ThongKeKhacModel> lst;

        WEBParamCollection Params = WEBParamCollection.getInstance();
        Params.add(("-1".equals(this.getCpid()) ? "" : this.getCpid()));
        Params.add(("-1".equals(this.getGameID()) ? "" : this.getGameID()));
        Params.add(this.getTuNgay());
        Params.add(this.getDenNgay());
        lst = DAL.executeQuery("{call RPT_ThongKeKhac_Chart_thang_ARPU(?,?,?,?)}", Command.sqlStoredProcedure, Params, RPT_ThongKeKhacModel.class);


        if(Sys_NguoiDungController.findUser().isIsAdmin())
        {
            List<RPT_ThongKeKhacModel> lst1=DAL.executeQuery("Select distinct CPID,CPName from users_report where users_report.CPID<>''",RPT_ThongKeKhacModel.class);
            for(RPT_ThongKeKhacModel m:lst1)
            {
                LineChartSeries l=new LineChartSeries();
                l.setLabel("Số ARPU theo " + m.getCpName());
                int i=0;
                boolean bln=false;
                while(i<lst.size())
                {
                     if(!l.getData().containsKey(lst.get(i).getThang()))
                    {
                        l.set(lst.get(i).getThang(), 0);
                        l.setShowLine(true);
                    }
                    if(lst.get(i).getCpid() == null ? m.getCpid() == null : lst.get(i).getCpid().equals(m.getCpid()))
                    {
                         l.set(lst.get(i).getThang(), lst.get(i).getSoTien()/(lst.get(i).getSoLuong()<=0?1:lst.get(i).getSoLuong()));
                         l.setShowLine(true);
                         bln=true;
                    }
                    i++;
                    
                   
                }
                  if(bln)
                    c.addSeries(l);
            }
            
            LineChartSeries l1=new LineChartSeries();
            l1.setLabel("Tổng số ARPU");
            int i=0;
            while(i<lst.size())
            {

                  l1.set(lst.get(i).getThang(), lst.get(i).getTongCong());
                 l1.setShowLine(true);
                     i++;
             
                  
            }
            
            
             c.addSeries(l1);
        }
        else
        {
            LineChartSeries l=new LineChartSeries();
            //LineChartSeries l1=new LineChartSeries();

            boolean bln=false;
            //l1.setLabel("Tổng số user nạp tiền");
          for (RPT_ThongKeKhacModel m : lst) {
              if(!bln)
              {
                  l.setLabel("CP Name " + m.getCpName());
                  bln=true;
              }
              l.setShowLine(true);
              l.set(m.getThang(), m.getSoLuong());

//              l1.setShowLine(true);
//              l1.set(m.getThoiGian(), m.getTongCong());

          }
          c.addSeries(l);
         // c.addSeries(l1);

        }
        
      
        return c;
    }
    
    
    public CartesianChartModel RPT_ThongKeKhac_Chart_BIT_line_ngay() throws SQLException {
        CartesianChartModel c = new CartesianChartModel();
        List<RPT_ThongKeKhacModel> lst;

        WEBParamCollection Params = WEBParamCollection.getInstance();
        Params.add(("-1".equals(this.getCpid()) ? "" : this.getCpid()));
        Params.add(("-1".equals(this.getGameID()) ? "" : this.getGameID()));
        Params.add(this.getTuNgay());
        Params.add(this.getDenNgay());
        lst = DAL.executeQuery("{call RPT_ThongKeKhac_Chart_ngay_BIT(?,?,?,?)}", Command.sqlStoredProcedure, Params, RPT_ThongKeKhacModel.class);


        if(Sys_NguoiDungController.findUser().isIsAdmin())
        {
            List<RPT_ThongKeKhacModel> lst1=DAL.executeQuery("Select distinct CPID,CPName from users_report where users_report.CPID<>''",RPT_ThongKeKhacModel.class);
            for(RPT_ThongKeKhacModel m:lst1)
            {
                LineChartSeries l=new LineChartSeries();
                l.setLabel("Số bit theo " + m.getCpName());
                int i=0;
                boolean bln=false;
                while(i<lst.size())
                {
                     if(!l.getData().containsKey(Utilities.parseDateTime(lst.get(i).getNgay(), "dd/MM")))
                    {
                        l.set(Utilities.parseDateTime(lst.get(i).getNgay(), "dd/MM"), 0);
                        l.setShowLine(true);
                    }
                    if(lst.get(i).getCpid() == null ? m.getCpid() == null : lst.get(i).getCpid().equals(m.getCpid()))
                    {
                         l.set(Utilities.parseDateTime(lst.get(i).getNgay(), "dd/MM"), lst.get(i).getSoTien());
                         l.setShowLine(true);
                         bln=true;
                    }
                    i++;
                    
                   
                }
                  if(bln)
                    c.addSeries(l);
            }
            
            LineChartSeries l1=new LineChartSeries();
            l1.setLabel("Tổng số bit");
            int i=0;
            while(i<lst.size())
            {

                  l1.set(Utilities.parseDateTime(lst.get(i).getNgay(), "dd/MM"), lst.get(i).getTongCong());
                 l1.setShowLine(true);
                     i++;
             
                  
            }
            
            
             c.addSeries(l1);
        }
        else
        {
            LineChartSeries l=new LineChartSeries();
            //LineChartSeries l1=new LineChartSeries();

            l.setLabel("Số bit theo CP");
            //l1.setLabel("Tổng số user nạp tiền");
          for (RPT_ThongKeKhacModel m : lst) {

              l.setShowLine(true);
              l.set(Utilities.parseDateTime(m.getNgay(), "dd/MM"), m.getSoTien());

//              l1.setShowLine(true);
//              l1.set(m.getThoiGian(), m.getTongCong());

          }
          c.addSeries(l);
         // c.addSeries(l1);

        }
        
      
        return c;
    }
     public CartesianChartModel RPT_ThongKeKhac_Chart_BIT_line_thang() throws SQLException {
        CartesianChartModel c = new CartesianChartModel();
        List<RPT_ThongKeKhacModel> lst;

        WEBParamCollection Params = WEBParamCollection.getInstance();
        Params.add(("-1".equals(this.getCpid()) ? "" : this.getCpid()));
        Params.add(("-1".equals(this.getGameID()) ? "" : this.getGameID()));
        Params.add(this.getTuNgay());
        Params.add(this.getDenNgay());
        lst = DAL.executeQuery("{call RPT_ThongKeKhac_Chart_thang_BIT(?,?,?,?)}", Command.sqlStoredProcedure, Params, RPT_ThongKeKhacModel.class);


        if(Sys_NguoiDungController.findUser().isIsAdmin())
        {
            List<RPT_ThongKeKhacModel> lst1=DAL.executeQuery("Select distinct CPID,CPName from users_report where users_report.CPID<>''",RPT_ThongKeKhacModel.class);
            for(RPT_ThongKeKhacModel m:lst1)
            {
                LineChartSeries l=new LineChartSeries();
                l.setLabel("Số bit theo " + m.getCpName());
                int i=0;
                boolean bln=false;
                while(i<lst.size())
                {
                     if(!l.getData().containsKey(lst.get(i).getThang()))
                    {
                        l.set(lst.get(i).getThang(), 0);
                        l.setShowLine(true);
                    }
                    if(lst.get(i).getCpid() == null ? m.getCpid() == null : lst.get(i).getCpid().equals(m.getCpid()))
                    {
                         l.set(lst.get(i).getThang(), lst.get(i).getSoTien());
                         l.setShowLine(true);
                         bln=true;
                    }
                    i++;
                    
                   
                }
                  if(bln)
                    c.addSeries(l);
            }
            
            LineChartSeries l1=new LineChartSeries();
            l1.setLabel("Tổng số bit");
            int i=0;
            while(i<lst.size())
            {

                  l1.set(lst.get(i).getThang(), lst.get(i).getTongCong());
                 l1.setShowLine(true);
                     i++;
             
                  
            }
            
            
             c.addSeries(l1);
        }
        else
        {
            LineChartSeries l=new LineChartSeries();
            //LineChartSeries l1=new LineChartSeries();

            l.setLabel("Số bit theo CP");
            //l1.setLabel("Tổng số user nạp tiền");
          for (RPT_ThongKeKhacModel m : lst) {

              l.setShowLine(true);
              l.set(m.getThang(), m.getSoTien());

//              l1.setShowLine(true);
//              l1.set(m.getThoiGian(), m.getTongCong());

          }
          c.addSeries(l);
         // c.addSeries(l1);

        }
        
      
        return c;
    }
    
    
    public CartesianChartModel RPT_ThongKeKhac_Chart_ARPU_os_line_ngay() throws SQLException {
        CartesianChartModel c = new CartesianChartModel();
        List<RPT_ThongKeKhacModel> lst;

        WEBParamCollection Params = WEBParamCollection.getInstance();
        Params.add(("-1".equals(this.getCpid()) ? "" : this.getCpid()));
        Params.add(("-1".equals(this.getGameID()) ? "" : this.getGameID()));
        Params.add(this.getTuNgay());
        Params.add(this.getDenNgay());
        lst = DAL.executeQuery("{call RPT_ThongKeKhac_Chart_ngay_ARPU_OS(?,?,?,?)}", Command.sqlStoredProcedure, Params, RPT_ThongKeKhacModel.class);


        if(Sys_NguoiDungController.findUser().isIsAdmin())
        {
           
                LineChartSeries l_iOS=new LineChartSeries("ARPU theo iOS");
                LineChartSeries l_Android=new LineChartSeries("ARPU theo Android");
                LineChartSeries l_WP=new LineChartSeries("ARPU theo Windows Phone");
                LineChartSeries l_PC=new LineChartSeries("ARPU theo PC");
               
                
                int i=0;
                boolean bln_iOS=false;
                boolean bln_Android=false;
                boolean bln_WP=false;
                boolean bln_PC=false;
                
                while(i<lst.size())
                {
                    if(!l_iOS.getData().containsKey(Utilities.parseDateTime(lst.get(i).getNgay(), "dd/MM")))
                    {
                        l_iOS.set(Utilities.parseDateTime(lst.get(i).getNgay(), "dd/MM"), 0);
                        l_iOS.setShowLine(true);
                    }
                    if(!l_Android.getData().containsKey(Utilities.parseDateTime(lst.get(i).getNgay(), "dd/MM")))
                    {
                        l_Android.set(Utilities.parseDateTime(lst.get(i).getNgay(), "dd/MM"), 0);
                        l_Android.setShowLine(true);
                    }
                    if(!l_WP.getData().containsKey(Utilities.parseDateTime(lst.get(i).getNgay(), "dd/MM")))
                    {
                        l_WP.set(Utilities.parseDateTime(lst.get(i).getNgay(), "dd/MM"), 0);
                        l_WP.setShowLine(true);
                    }
                    if(!l_PC.getData().containsKey(Utilities.parseDateTime(lst.get(i).getNgay(), "dd/MM")))
                    {
                        l_PC.set(Utilities.parseDateTime(lst.get(i).getNgay(), "dd/MM"), 0);
                        l_PC.setShowLine(true);
                    }
                    
                    
                    if(lst.get(i).getHDH().equals("iphone") || lst.get(i).getHDH().equals("ipad"))
                    {
                         l_iOS.set(Utilities.parseDateTime(lst.get(i).getNgay(), "dd/MM"), lst.get(i).getSoTien()/lst.get(i).getSoLuong());
                         l_iOS.setShowLine(true);
                         bln_iOS=true;
                    }
                    
                    if(lst.get(i).getHDH().equals("android"))
                    {
                         l_Android.set(Utilities.parseDateTime(lst.get(i).getNgay(), "dd/MM"), lst.get(i).getSoTien()/lst.get(i).getSoLuong());
                         l_Android.setShowLine(true);
                         bln_Android=true;
                    }
                    if(lst.get(i).getHDH().equals("wp"))
                    {
                         l_WP.set(Utilities.parseDateTime(lst.get(i).getNgay(), "dd/MM"), lst.get(i).getSoTien()/lst.get(i).getSoLuong());
                         l_WP.setShowLine(true);
                         bln_WP=true;
                    }
                    if(lst.get(i).getHDH().equals("windows"))
                    {
                         l_PC.set(Utilities.parseDateTime(lst.get(i).getNgay(), "dd/MM"), lst.get(i).getSoTien()/lst.get(i).getSoLuong());
                         l_PC.setShowLine(true);
                         bln_PC=true;
                    }
                    i++;
                }
                if(bln_Android)
                  c.addSeries(l_Android);
                if(bln_iOS)
                  c.addSeries(l_iOS);
                if(bln_WP)
                  c.addSeries(l_WP);
                if(bln_PC)
                  c.addSeries(l_PC);
        }
        else
        {
            LineChartSeries l=new LineChartSeries();
            //LineChartSeries l1=new LineChartSeries();

            l.setLabel("Số ARPU theo CP");
            //l1.setLabel("Tổng số user nạp tiền");
          for (RPT_ThongKeKhacModel m : lst) {

              l.setShowLine(true);
              l.set(m.getNgay(), m.getSoTien()/m.getSoLuong());

//              l1.setShowLine(true);
//              l1.set(m.getThoiGian(), m.getTongCong());

          }
          c.addSeries(l);
         // c.addSeries(l1);

        }
        
      
        return c;
    }
    
     public CartesianChartModel RPT_ThongKeKhac_Chart_ARPU_os_line_thang() throws SQLException {
        CartesianChartModel c = new CartesianChartModel();
        List<RPT_ThongKeKhacModel> lst;

        WEBParamCollection Params = WEBParamCollection.getInstance();
        Params.add(("-1".equals(this.getCpid()) ? "" : this.getCpid()));
        Params.add(("-1".equals(this.getGameID()) ? "" : this.getGameID()));
        Params.add(this.getTuNgay());
        Params.add(this.getDenNgay());
        lst = DAL.executeQuery("{call RPT_ThongKeKhac_Chart_thang_ARPU_OS(?,?,?,?)}", Command.sqlStoredProcedure, Params, RPT_ThongKeKhacModel.class);


        if(Sys_NguoiDungController.findUser().isIsAdmin())
        {
           
                LineChartSeries l_iOS=new LineChartSeries("ARPU theo iOS");
                LineChartSeries l_Android=new LineChartSeries("ARPU theo Android");
                LineChartSeries l_WP=new LineChartSeries("ARPU theo Windows Phone");
                LineChartSeries l_PC=new LineChartSeries("ARPU theo PC");
               
                
                int i=0;
                boolean bln_iOS=false;
                boolean bln_Android=false;
                boolean bln_WP=false;
                boolean bln_PC=false;
                
                while(i<lst.size())
                {
                    if(!l_iOS.getData().containsKey(lst.get(i).getThang()))
                    {
                        l_iOS.set(lst.get(i).getThang(), 0);
                        l_iOS.setShowLine(true);
                    }
                    if(!l_Android.getData().containsKey(lst.get(i).getThang()))
                    {
                        l_Android.set(lst.get(i).getThang(), 0);
                        l_Android.setShowLine(true);
                    }
                    if(!l_WP.getData().containsKey(lst.get(i).getThang()))
                    {
                        l_WP.set(lst.get(i).getThang(), 0);
                        l_WP.setShowLine(true);
                    }
                    if(!l_PC.getData().containsKey(lst.get(i).getThang()))
                    {
                        l_PC.set(lst.get(i).getThang(), 0);
                        l_PC.setShowLine(true);
                    }
                    
                    
                    if(lst.get(i).getHDH().equals("iphone") || lst.get(i).getHDH().equals("ipad"))
                    {
                         l_iOS.set(lst.get(i).getThang(), lst.get(i).getSoTien()/lst.get(i).getSoLuong());
                         l_iOS.setShowLine(true);
                         bln_iOS=true;
                    }
                    
                    if(lst.get(i).getHDH().equals("android"))
                    {
                         l_Android.set(lst.get(i).getThang(), lst.get(i).getSoTien()/lst.get(i).getSoLuong());
                         l_Android.setShowLine(true);
                         bln_Android=true;
                    }
                    if(lst.get(i).getHDH().equals("wp"))
                    {
                         l_WP.set(lst.get(i).getThang(), lst.get(i).getSoTien()/lst.get(i).getSoLuong());
                         l_WP.setShowLine(true);
                         bln_WP=true;
                    }
                    if(lst.get(i).getHDH().equals("windows"))
                    {
                         l_PC.set(lst.get(i).getThang(), lst.get(i).getSoTien()/lst.get(i).getSoLuong());
                         l_PC.setShowLine(true);
                         bln_PC=true;
                    }
                    i++;
                }
                if(bln_Android)
                  c.addSeries(l_Android);
                if(bln_iOS)
                  c.addSeries(l_iOS);
                if(bln_WP)
                  c.addSeries(l_WP);
                if(bln_PC)
                  c.addSeries(l_PC);
        }
        else
        {
            LineChartSeries l=new LineChartSeries();
            //LineChartSeries l1=new LineChartSeries();

            l.setLabel("Số ARPU theo CP");
            //l1.setLabel("Tổng số user nạp tiền");
          for (RPT_ThongKeKhacModel m : lst) {

              l.setShowLine(true);
              l.set(m.getNgay(), m.getSoTien()/m.getSoLuong());

//              l1.setShowLine(true);
//              l1.set(m.getThoiGian(), m.getTongCong());

          }
          c.addSeries(l);
         // c.addSeries(l1);

        }
        
      
        return c;
    }
    
    
     
      public CartesianChartModel RPT_ThongKeKhac_Chart_BAC_line_ngay() throws SQLException {
        CartesianChartModel c = new CartesianChartModel();
        List<RPT_ThongKeKhacModel> lst;

        WEBParamCollection Params = WEBParamCollection.getInstance();
        Params.add(("-1".equals(this.getCpid()) ? "" : this.getCpid()));
        Params.add(("-1".equals(this.getGameID()) ? "" : this.getGameID()));
        Params.add(this.getTuNgay());
        Params.add(this.getDenNgay());
        lst = DAL.executeQuery("{call RPT_ThongKeKhac_Chart_ngay_BAC(?,?,?,?)}", Command.sqlStoredProcedure, Params, RPT_ThongKeKhacModel.class);


        if(Sys_NguoiDungController.findUser().isIsAdmin())
        {
            List<RPT_ThongKeKhacModel> lst1=DAL.executeQuery("Select distinct CPID,CPName from users_report where users_report.CPID<>''",RPT_ThongKeKhacModel.class);
            for(RPT_ThongKeKhacModel m:lst1)
            {
                LineChartSeries l=new LineChartSeries();
                l.setLabel("Số bac theo " + m.getCpName());
                int i=0;
                boolean bln=false;
                while(i<lst.size())
                {
                     if(!l.getData().containsKey(Utilities.parseDateTime(lst.get(i).getNgay(), "dd/MM")))
                    {
                        l.set(Utilities.parseDateTime(lst.get(i).getNgay(), "dd/MM"), 0);
                        l.setShowLine(true);
                    }
                    if(lst.get(i).getCpid() == null ? m.getCpid() == null : lst.get(i).getCpid().equals(m.getCpid()))
                    {
                         l.set(Utilities.parseDateTime(lst.get(i).getNgay(), "dd/MM"), lst.get(i).getSoTien());
                         l.setShowLine(true);
                         bln=true;
                    }
                    i++;
                    
                   
                }
                  if(bln)
                    c.addSeries(l);
            }
            
            LineChartSeries l1=new LineChartSeries();
            l1.setLabel("Tổng số bac");
            int i=0;
            while(i<lst.size())
            {

                  l1.set(Utilities.parseDateTime(lst.get(i).getNgay(), "dd/MM"), lst.get(i).getTongCong());
                 l1.setShowLine(true);
                     i++;
             
                  
            }
            
            
             c.addSeries(l1);
        }
        else
        {
            LineChartSeries l=new LineChartSeries();
            //LineChartSeries l1=new LineChartSeries();

            l.setLabel("Số bac theo CP");
            //l1.setLabel("Tổng số user nạp tiền");
          for (RPT_ThongKeKhacModel m : lst) {

              l.setShowLine(true);
              l.set(Utilities.parseDateTime(m.getNgay(), "dd/MM"), m.getSoTien());

//              l1.setShowLine(true);
//              l1.set(m.getThoiGian(), m.getTongCong());

          }
          c.addSeries(l);
         // c.addSeries(l1);

        }
        
      
        return c;
    }
     public CartesianChartModel RPT_ThongKeKhac_Chart_BAC_line_thang() throws SQLException {
        CartesianChartModel c = new CartesianChartModel();
        List<RPT_ThongKeKhacModel> lst;

        WEBParamCollection Params = WEBParamCollection.getInstance();
        Params.add(("-1".equals(this.getCpid()) ? "" : this.getCpid()));
        Params.add(("-1".equals(this.getGameID()) ? "" : this.getGameID()));
        Params.add(this.getTuNgay());
        Params.add(this.getDenNgay());
        lst = DAL.executeQuery("{call RPT_ThongKeKhac_Chart_thang_BAC(?,?,?,?)}", Command.sqlStoredProcedure, Params, RPT_ThongKeKhacModel.class);


        if(Sys_NguoiDungController.findUser().isIsAdmin())
        {
            List<RPT_ThongKeKhacModel> lst1=DAL.executeQuery("Select distinct CPID,CPName from users_report where users_report.CPID<>''",RPT_ThongKeKhacModel.class);
            for(RPT_ThongKeKhacModel m:lst1)
            {
                LineChartSeries l=new LineChartSeries();
                l.setLabel("Số bac theo " + m.getCpName());
                int i=0;
                boolean bln=false;
                while(i<lst.size())
                {
                     if(!l.getData().containsKey(lst.get(i).getThang()))
                    {
                        l.set(lst.get(i).getThang(), 0);
                        l.setShowLine(true);
                    }
                    if(lst.get(i).getCpid() == null ? m.getCpid() == null : lst.get(i).getCpid().equals(m.getCpid()))
                    {
                         l.set(lst.get(i).getThang(), lst.get(i).getSoTien());
                         l.setShowLine(true);
                         bln=true;
                    }
                    i++;
                    
                   
                }
                  if(bln)
                    c.addSeries(l);
            }
            
            LineChartSeries l1=new LineChartSeries();
            l1.setLabel("Tổng số bac");
            int i=0;
            while(i<lst.size())
            {

                  l1.set(lst.get(i).getThang(), lst.get(i).getTongCong());
                 l1.setShowLine(true);
                     i++;
             
                  
            }
            
            
             c.addSeries(l1);
        }
        else
        {
            LineChartSeries l=new LineChartSeries();
            //LineChartSeries l1=new LineChartSeries();

            l.setLabel("Số bac theo CP");
            //l1.setLabel("Tổng số user nạp tiền");
          for (RPT_ThongKeKhacModel m : lst) {

              l.setShowLine(true);
              l.set(m.getThang(), m.getSoTien());

//              l1.setShowLine(true);
//              l1.set(m.getThoiGian(), m.getTongCong());

          }
          c.addSeries(l);
         // c.addSeries(l1);

        }
        
      
        return c;
    }
     
     
     

    public void cmd_RPT_ThongKeKhac_Excel_Click(ActionEvent event) throws SQLException, ParseException {
        Map mapParams = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
        this.setCpid(String.valueOf(mapParams.get("CPID")));
        this.setGameID(String.valueOf(mapParams.get("Game")));
        this.setLoaiThongKe(String.valueOf(mapParams.get("LoaiTK")));
        String strTuNgay = String.valueOf(mapParams.get("TuNgay"));
        String strDenNgay = String.valueOf(mapParams.get("DenNgay"));
        setTuNgay(Utilities.parseDate(strTuNgay, "dd/MM/yyyy"));
        setDenNgay(Utilities.parseDate(strDenNgay, "dd/MM/yyyy"));
        
        WEBParamCollection Params=WEBParamCollection.getInstance();
        
        Params.add(("-1".equals(this.getCpid()) ? "" : this.getCpid()));
        Params.add(("-1".equals(this.getGameID()) ? "" : this.getGameID()));
        Params.add(("-1".equals(this.getLoaiThongKe()) ? "" : this.getLoaiThongKe()));
        Params.add(this.getTuNgay());
        Params.add(this.getDenNgay());
        List<RPT_ThongKeKhacModel>lst;
        lst = DAL.executeQuery("{call RPT_ThongKeKhac(?,?,?,?,?)}", Command.sqlStoredProcedure, Params, RPT_ThongKeKhacModel.class);
        
        switch (this.getLoaiThongKe()) {
            case "ARPU":
                setFileExporter(controller.thongKeKhacToExcel_ARPU(tuNgay, denNgay, lst));
                break;
            case "BIT":
                setFileExporter(controller.thongKeKhacToExcel_BIT(tuNgay, denNgay, lst));
                break;
            case "BAC":
                setFileExporter(controller.thongKeKhacToExcel_BAC(tuNgay, denNgay, lst));
                break;
            default:
                setFileExporter(controller.thongKeKhacToExcel(tuNgay, denNgay, lst));
                break;
        }
        
        
        if (getFileExporter() != null) {
            try {
                Utilities.deleteFile(new File(controller.getLocalPath() + "/" + getFileExporter().getName()));
            } catch (IOException ex) {
                Logger.getLogger(ReportController.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    public void cmd_RPT_ThongKeKhac_ThongKe_Click(ActionEvent event) throws SQLException, ParseException {
        Map mapParams = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
        this.setCpid(String.valueOf(mapParams.get("CPID")));
        this.setGameID(String.valueOf(mapParams.get("Game")));
        this.setLoaiThongKe(String.valueOf(mapParams.get("LoaiTK")));
        String strTuNgay = String.valueOf(mapParams.get("TuNgay"));
        String strDenNgay = String.valueOf(mapParams.get("DenNgay"));
        setTuNgay(Utilities.parseDate(strTuNgay, "dd/MM/yyyy"));
        setDenNgay(Utilities.parseDate(strDenNgay, "dd/MM/yyyy"));
        switch (this.getLoaiThongKe()) {
            case "ARPU":
                this.setPage("/layout/Web/thongkekhac_arpu.xhtml");
                break;
            case "BIT":
                this.setPage("/layout/Web/thongkekhac_bit.xhtml");
                break;
            case "BAC":
                this.setPage("/layout/Web/thongkekhac_bac.xhtml");
                break;
            default:
                this.setPage("/layout/Web/thongkekhac.xhtml");
                break;
        }
    }

    public void cmd_RPT_ThongKeKhac_Chart_Click(ActionEvent event) throws SQLException, ParseException {
        Map mapParams = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
        this.setCpid(String.valueOf(mapParams.get("CPID")));
        this.setGameID(String.valueOf(mapParams.get("Game")));
        this.setLoaiThongKe(String.valueOf(mapParams.get("LoaiTK")));
        String strTuNgay = String.valueOf(mapParams.get("TuNgay"));
        String strDenNgay = String.valueOf(mapParams.get("DenNgay"));
        setTuNgay(Utilities.parseDate(strTuNgay, "dd/MM/yyyy"));
        setDenNgay(Utilities.parseDate(strDenNgay, "dd/MM/yyyy"));
         switch (this.getLoaiThongKe()) {
            case "ARPU":
                this.setPage("/layout/Chart/thongkekhac_arpu.xhtml");
                break;
            case "BIT":
                this.setPage("/layout/Chart/thongkekhac_bit.xhtml");
                break;
            case "BAC":
                this.setPage("/layout/Chart/thongkekhac_bac.xhtml");
                break;
            case "DAU":
                this.setPage("/layout/Chart/thongkekhac_dau.xhtml");
                break;
        }
        
    }

    /**
     * @return the cpid
     */
    public String getCpid() {
        return cpid;
    }

    /**
     * @param cpid the cpid to set
     */
    public void setCpid(String cpid) {
        this.cpid = cpid;
    }

    /**
     * @return the hdh
     */
    public String getHdh() {
        return hdh;
    }

    /**
     * @param hdh the hdh to set
     */
    public void setHdh(String hdh) {
        this.hdh = hdh;
    }

    /**
     * @return the gameID
     */
    public String getGameID() {
        return gameID;
    }

    /**
     * @param gameID the gameID to set
     */
    public void setGameID(String gameID) {
        this.gameID = gameID;
    }

    /**
     * @return the loaiThongKe
     */
    public String getLoaiThongKe() {
        return loaiThongKe;
    }

    /**
     * @param loaiThongKe the loaiThongKe to set
     */
    public void setLoaiThongKe(String loaiThongKe) {
        this.loaiThongKe = loaiThongKe;
    }

    /**
     * @return the tuNgay
     */
    public Date getTuNgay() {
        return tuNgay;
    }

    /**
     * @param tuNgay the tuNgay to set
     */
    public void setTuNgay(Date tuNgay) {
        this.tuNgay = tuNgay;
    }

    /**
     * @return the denNgay
     */
    public Date getDenNgay() {
        return denNgay;
    }

    /**
     * @param denNgay the denNgay to set
     */
    public void setDenNgay(Date denNgay) {
        this.denNgay = denNgay;
    }

    /**
     * @return the giaTriTheNap
     */
    public long getGiaTriTheNap() {
        return giaTriTheNap;
    }

    /**
     * @param giaTriTheNap the giaTriTheNap to set
     */
    public void setGiaTriTheNap(long giaTriTheNap) {
        this.giaTriTheNap = giaTriTheNap;
    }

    /**
     * @return the congTT
     */
    public String getCongTT() {
        return congTT;
    }

    /**
     * @param congTT the congTT to set
     */
    public void setCongTT(String congTT) {
        this.congTT = congTT;
    }

    /**
     * @return the telco
     */
    public String getTelco() {
        return telco;
    }

    /**
     * @param telco the telco to set
     */
    public void setTelco(String telco) {
        this.telco = telco;
    }

    public StreamedContent getFileExporter() {
        return fileExporter;
    }

    public void setFileExporter(StreamedContent fileExporter) {
        this.fileExporter = fileExporter;
    }

    /**
     * @return the tong1
     */
    public long getTong1() {
        return tong1;
    }

    /**
     * @param tong1 the tong1 to set
     */
    public void setTong1(long tong1) {
        this.tong1 = tong1;
    }

    /**
     * @return the tong2
     */
    public long getTong2() {
        return tong2;
    }

    /**
     * @param tong2 the tong2 to set
     */
    public void setTong2(long tong2) {
        this.tong2 = tong2;
    }

    /**
     * @return the tong3
     */
    public long getTong3() {
        return tong3;
    }

    /**
     * @param tong3 the tong3 to set
     */
    public void setTong3(long tong3) {
        this.tong3 = tong3;
    }

    /**
     * @return the tong4
     */
    public long getTong4() {
        return tong4;
    }

    /**
     * @param tong4 the tong4 to set
     */
    public void setTong4(long tong4) {
        this.tong4 = tong4;
    }

    /**
     * @return the loaiBD
     */
    public String getLoaiBD() {
        return loaiBD;
    }

    /**
     * @param loaiBD the loaiBD to set
     */
    public void setLoaiBD(String loaiBD) {
        this.loaiBD = loaiBD;
    }
}
